package mysql

import (
	"database/sql"
	"fmt"

	_ "github.com/go-sql-driver/mysql"
)

var (
	db  *sql.DB
	err error
)

func init() {
	db, err = sql.Open("mysql", "root:cm2213@tcp(127.0.0.1:3306)/db_tongxing?charset=utf8")
	if err != nil {
		fmt.Println("Connect mysql error: ", err)
		panic(err)
	}
	err = db.Ping()
	if err != nil {
		panic(err)
	}
}

// DBConn : 获取数据库句柄
func DBConn() *sql.DB {
	return db
}
